# 44. 园区参观路径

44

const readline = require('readline');
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
});
let input = [];
rl.on('line', function(num) {
    input.push(num.split(' ').map(Number));
});
rl.on('close', () => {
    let m = input[0][0];
    let n = input[0][1];
    let grid = input.slice(1);
    let dp = Array.from({length: m}, () => Array(n).fill(0));
    for(let i=0; i<m; i++) {
        for(let j=0; j<n; j++) {
            if (grid[i][j] === 0) {
                if (i===0 && j===0) {
                    dp[i][j] = 1;
                } else if (i===0) {
                    dp[i][j] = dp[i][j-1];
                } else if (j===0) {
                    dp[i][j] = dp[i-1][j];
                } else {
                    dp[i][j] = dp[i-1][j] + dp[i][j-1];
                }
            }
        }
    }
    console.log(dp[m-1][n-1]);
})
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31